import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp.util import login_required
from models import *
from datetime import datetime
import logging

class ProjectHandler(webapp.RequestHandler):

    @login_required
    def get(self):
        self.response.out.write(
            template.render('templates/project_form.html', {}))
    
    def post(self):
        user = users.get_current_user()
        time = datetime.now()
        project = Project(
            name=self.request.get('name'),
            owner=user,
            secret_key=self.request.get('secret_key'),
            moddate=time,
            test_path=self.request.get('test_path'),
            source_path=self.request.get('source_path'),
        )
        project.put()
        

def main():
    application = webapp.WSGIApplication([('/projects/add', ProjectHandler)],
                               debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
